package com.meng.message.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.context.annotation.Bean;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @Author huangxiong
 * @Date 2019/6/13 0013
 **/
@SpringBootConfiguration
@EnableSwagger2
public class SwaggerConfig {

    @Value("${spring.profiles.active}")
    private String active;

    @Bean
    public Docket createRestApi() {

        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .enable(!"prod".equals(active))
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.meng.system.controller"))
                .paths(PathSelectors.any())
                .build();
                //.globalOperationParameters(setHeaderToken());
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("系统服务模块接口API")
                .description("©2019 Copyright. Powered By hua-cloud")
                .build();
    }
}
